package com.example.demo.design.demo01_simpleFactory;

/**
 * Created by 蔡超 on 2018/10/1.
 */
public class OPerationFactory {

    public static OperationI createOperation(String operation){
        OperationI operationI = null;
        switch (operation){
            case "+":operationI = new OperationAdd(); break;
            case "-":operationI = new OperationSubtract(); break;
            case "*":operationI = new OperationMultiply(); break;
            case "/":operationI = new OperationDivide(); break;
        }
        return operationI;
    }

    public static void main(String[] args) {
        Double a = 2.1;
        Double b = 2d;
        OperationI operationAdd = OPerationFactory.createOperation("+");
        Double result = operationAdd.calculation(a,b);
        System.out.println("result: " + result);
    }

}
